﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using m4aSharp;

namespace m4aTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {

        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void ReadAnAtom()
        {
            m4aFile file = new m4aFile(@"C:\temp\song.m4a");
            file.Load();

            Atom atom = file.GetAtom("moov.udta.meta.ilst.©nam.data");
            Assert.IsNotNull(atom);

            object name = atom.InterpretData();
            Assert.IsNotNull(name);

            Assert.AreEqual(name.ToString(), "Absolutely (Story Of A Girl)");
        }

        [TestMethod]
        public void CompareAtomToTag()
        {
            m4aFile file = new m4aFile(@"C:\temp\song.m4a");
            file.Load();

            Atom atom = file.GetAtom("moov.udta.meta.ilst.©nam.data");
            Assert.IsNotNull(atom);

            object name = atom.InterpretData();
            Assert.IsNotNull(name);

            m4aTags tags = new m4aTags(@"C:\temp\song.m4a");
            tags.Load();

            Assert.IsTrue(tags.Tags.ContainsKey("Title"));
            object tag = tags.Tags["Title"];

            Assert.IsNotNull(tag);
            Assert.AreEqual(name, tag);
        }

        [TestMethod]
        public void CreationTime()
        {
            m4aTags tags = new m4aTags(@"C:\temp\song.m4a");
            tags.Load();
            Assert.IsTrue(tags.Tags.ContainsKey("CreationTime")); 
            object tag = tags.Tags["CreationTime"];

            Assert.IsNotNull(tag);
            DateTime date = (DateTime)tag;

            Assert.IsTrue(date.Month == 8);
            Assert.IsTrue(date.Day == 16);
            Assert.IsTrue(date.Year == 2009);
        }

        [TestMethod]
        public void GetGenreString()
        {
            m4aTags tags = new m4aTags(@"C:\temp\song.m4a");
            tags.Load();
            Assert.IsTrue(tags.Tags.ContainsKey("WM/Genre"));
            object tag = tags.Tags["WM/Genre"];

            Assert.IsNotNull(tag);
            Assert.AreEqual(tag, "Rock");
        }
    }
}
